package com.huike.web.controller.report;


import com.huike.clues.domain.TbAssignRecord;
import com.huike.clues.domain.TbDate;
import com.huike.clues.domain.cdndr;
import com.huike.clues.domain.vo.TbAssignRecordVo;
import com.huike.clues.service.ITbClueService;
import com.huike.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/index")
public class IndexController {
    @Autowired
     private ITbClueService iTbClueService;

    @GetMapping("/salesStatistic")
    public AjaxResult lh(TbDate tbDate){
        List<cdndr> cdndrs = new ArrayList<>();

        List<TbAssignRecordVo> tbAssignRecordVos = iTbClueService.selectByCreateTimeList(tbDate);
        for (TbAssignRecordVo tbAssignRecordVo : tbAssignRecordVos) {
            int i=0;
            cdndr c1 = new cdndr();

            String userName = tbAssignRecordVo.getUserName();
            Integer useAll = tbAssignRecordVo.getUseAll();

            String s = iTbClueService.selectBydeptid(tbAssignRecordVo.getDeptId().intValue());
            Integer i3 = iTbClueService.selectByName(s);

           List<Integer> integers = iTbClueService.selectByuserId(tbAssignRecordVo.getUserId().intValue());
            for (Integer integer : integers) {
                Integer i2 = iTbClueService.selectByCreateassignId(integer);
                i=i+i2;
            }

            double idouble=i;
            double udouble=useAll;
            double sum=(idouble/udouble)*100;
            sum=(double)Math.round(sum*100)/100;


            c1.setCreate_by(userName);
            c1.setDeptName(s);
            c1.setNum(i);
            c1.setDep_id(i3);
            c1.setRadio(sum);
            cdndrs.add(c1);
        }
         return AjaxResult.success(cdndrs);
    }
}
